<template>
  <div class="container">
    <div class="loginBox">
      <div class="title">登录页面</div>
      <el-form :label-position="labelPosition" label-width="100px" :model="formLabelAlign">
        <el-form-item label="学号/教工号">
          <el-input v-model="formLabelAlign.stuNo"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="formLabelAlign.password"></el-input>
        </el-form-item>
      </el-form>
      <div class="buttom">
        <el-button type="primary" @click="loginFN" round>登录</el-button>
        <el-button type="primary" @click="toRegister" round>注册</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { login } from '@/api/user'
export default {
  data() {
    return {
      labelPosition: 'left',
      formLabelAlign: {
        stuNo: '20191101390',
        password: 'admin'
      }
    }
  },
  methods: {
    toRegister() {
      this.$router.push('/register')
    },
    loginFN() {
      login(this.formLabelAlign).then(res => {
        if (res.data) {
          this.$message({
            message: res.msg,
            type: 'success'
          })
          this.$store.commit('user/setUser', res.data[0])
          this.$router.push('/home')
        } else {
          this.$message.error(res.msg)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url('@/assets/images/bg.webp');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  color: black;
  .loginBox {
    width: 400px;
    background-color: rgba(255, 255, 255, 0.5);
    padding: 10px;
    border-radius: 10px;
    .el-form-item__label {
      color: black !important;
    }
    .title {
      width: 100%;
      text-align: center;
      padding-bottom: 20px;
      font-size: 20px;
    }
    .buttom {
      width: 100%;
      display: flex;
      justify-content: center;
    }
  }
}
</style>